<template>
  <view class="edit-wrapper">
    <TopNav name="back">
      <text slot="title">分类管理</text>
    </TopNav>
    <TypeSection @getCategory="getCategory"/>
    <view class="tags-list">
      <view>
        <view v-for="tag in moldTags" :key="tag.id">
          <view class="tags">
            <Icon :iconName="tag.iconName"/>
            <text>{{tag.name}}</text>
          </view>
          <view :to="`${$route.path}/${tag.id}`">
            <Icon iconName="more"/>
          </view>
        </view>
      </view>
    </view>
    <view class="add_tag">
      <view :to="`${$route.path}/9999`">
        添加类别
      </view>
    </view>
  </view>
</template>

<script>
  import TopNav from '@/components/common/TopNav/TopNav';
  import TypeSection from '@/components/common/TypeSection/TypeSection';

  export default {
    components: {TypeSection, TopNav},
    computed:{
      tags() {
        return this.$store.state.tagList;
      },
      moldTags(){
        return this.tags.filter(tag => tag.mold === '-')
      }
    },
    methods:{
      getCategory(category) {
        this.moldTags = this.tags.filter(tag => tag.mold === category);
      }
    }
  }

</script>

<style lang="scss" scoped>
  .edit-wrapper {
    max-width: 520px;
    margin: 0 auto;
    background-color: #fff;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1;
    display: flex;
    flex-direction: column;

    .tags-list {
      flex: 1;
      overflow-y: auto;

      ul {
        display: flex;
        flex-direction: column;
        justify-content: center;
      }

      li {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        margin-left: 10px;

        > .tags {
          display: flex;
          align-items: center;

          > span {
            padding-left: 8px;
            font-size: 18px;
          }

          > .icon {
            width: 42px;
            height: 42px;
          }
        }

        .icon {
          width: 24px;
          height: 24px;
        }
      }
    }

    .add_tag {
      text-align: center;
      background-color: $uni-color-primary;
      font-size: 22px;
      padding: 14px 0;
    }
  }
</style>
